const router = require('koa-router')()

router.get('/', async (ctx, next) => {
  await ctx.render('index', {
    title: 'Hello Koa 2， 我来了啊!'
  })
})

router.get('/string', async (ctx, next) => {
  ctx.body = 'koa2 string'
})

router.get('/json', async (ctx, next) => {
  ctx.body = {
    title: 'koa2 json'
  }
})
router.get('/testAsync',async (ctx) =>{
  console.log('开始时间：'+ new Date().getTime());

  const a = await new Promise((resolve,reject)=>{
    setTimeout(()=> {
      console.log('1秒钟后'+new Date().getTime());
      resolve('aa')
    },1000)
  });
  const b = await 'bb';
  const c = await new Promise((resolve,reject)=>{
    setTimeout(()=> {
      console.log('2秒钟后'+new Date().getTime());
      resolve('cc')
    },2000)
  });
  console.log('页面写完了~~')
  ctx.body = {
    a,
    b,
    c
  }
})
module.exports = router;
